/**
 * 获取最近的日期
 * @param {Number} day 相对于今天的第几天 0表示今天 1表示明天 -1表示昨天
 * @param {String} sign 日期之间的分隔符号 默认为 /
 */

export const nearlyDate = (day, sign) => {
    if (isNaN(Number(day))) {
      return 'day参数格式错误！'
    }
    let today = new Date()
    let targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * Number(day)
    today.setTime(targetday_milliseconds) //注意，这行是关键代码
    let tMonth = today.getMonth()
    let tDate = today.getDate()
    tMonth = doHandleMonth(tMonth + 1)
    tDate = doHandleMonth(tDate)
    return tMonth + (sign ? sign : '/') + tDate
}

//补零
const doHandleMonth = (month) => {
    let m = month
    if (month.toString().length == 1) {
        m = "0" + month
    }
    return m
}